; *** Morris (Nine Holes, Three Men's Morris, Tapatan, Achi...)
; *** Copyright 1998-2002 Zillions Development
; v.2.0

; You need to purchase Zillions of Games to load this rules file
; Visit the Zillions web site at http://www.zillions-of-games.com

(version "2.0")
(translate
 ("Green" "绿棋")("Blue" "蓝棋")
 ("Three Men's Morris" "3子 - 方格棋盘")
 ("Nine Holes" "3子 - 自由移动 - 斜连无效")
 ("Les Pendus" "3子 - 自由移动 - 斜连有效")
 ("Les Pendus - Oldest Moves" "3子 - 自由移动 - 顺序移动")
 ("Tapatan" "3子 - 米字棋盘")
 ("Achi" "4子 - 米字棋盘")
 ("Tant Fant" "3子 - 米字棋盘 - 固定布局")
 ("Tant Fant - Diagonals Only" "3子 - 米字棋盘 - 仅斜连有效")
 ("Picaria" "4子 - 八方棋盘")
 ("Modern Seega" "3子 - 八方棋盘 - 固定布局")
 ("Tsoro Yematatu" "3子 - 金字塔棋盘")
)
; References:
;
; 'Tic Tac Toe' by Claudia Zaslavsky
; Thomas Y. Crowell, NY 1982
; ISBN 0-690-04316-3
;
; 'Medieval Games' by Jeffrey A. DeLuca, p.40-42
; Third Edition, Copyright 1995
;
; 'Hexaflagons and Other Mathematical Diversions' by Martin Gardner, p.38-40
;
; 'Africa Counts' by Claudia Zaslavsky, p.104-105\
; Copyright 1973 Prindle, Weber, & Schmit, Inc., Boston MA\
; ISBN 87150-160-0, LOC# 72-91248
;
; 'Ancient Puzzles' by Dominic Olivastro, p.71
; Bantum Books, NY 1993
; ISBN 0-553-37297-1
;
; 'Games of Many Nations' by Elvin Oscar Harbin, p.18-19
; Abingdon Press, NY, Nashville
; LOC# 54-8238


(define add-to-empty  ((verify empty?) add) )
(define add-to-empty2  ((verify empty?) (verify (not-position? last)) mark
                        to
                        a1 (while (on-board? next) 
                              (if friend?
                              (if mid-age? (set-attribute old? true) 
                                            (set-attribute mid-age? false)                                 
                              else
                              (if young? (set-attribute young? false) 
                                          (set-attribute mid-age? true) 
                               )))
                              next)
                        back add) )
   
(define shift         ($1 (verify empty?) add) )
(define slide         ($1 (verify empty?) add $1 (verify empty?) add) )
(define shift2         (mark (verify old?) 
                        from                   
                          $1 (verify empty?) to 
                          a1 (while (on-board? next) 
                              (if friend?
                               (if mid-age? (set-attribute old? true) 
                                            (set-attribute mid-age? false)
                                else
                                (if young? (set-attribute young? false) 
                                           (set-attribute mid-age? true) 
                                )
                               )
                              )
                              next) 
                        back 
                        $1
                        (set-attribute old? false) 
                        (set-attribute young? true)
                        add)  )

(define TMM-Grid
    (start-rectangle 7 7 100 100) ; top-left position
    (dimensions ("a/b/c" (116 0)) ("3/2/1" (0 116)) )
)
(define Tapatan-Grid
    (start-rectangle -11 -1 100 100) ; top-left position
    (dimensions ("a/b/c" (125 0)) ("3/2/1" (0 125)) )
)
(define Picaria-Grid
    (start-rectangle 27 27 100 100) ; top-left position
    (dimensions ("a/b/c" (112 0)) ("3/2/1" (0 112)) )
)

(define common-piece-stuff
    (name man)
	(image Green "images\Morris\Green_Pebble.bmp"  ;images/Greenball.bmp
		   Blue "images\Morris\Blue_Pebble.bmp")   ;images/Blueball.bmp
    (drops
        (move-type dropping)
        (add-to-empty)
    )
)
(define common-piece-stuff2
    (name man)
	(image Green "images\Morris\Green_Pebble.bmp"  ;images/Greenball.bmp
		   Blue "images\Morris\Blue_Pebble.bmp")   ;images/Blueball.bmp
    (attribute old? false)
    (attribute mid-age? false)
    (attribute young? true)
    (drops
        (move-type dropping)
        (add-to-empty2)
    )
)

; *** Three Men's Morris
(variant
    (title "Three Men's Morris")
	(description "每方持有3枚棋子，轮流落于棋盘上后，才可按线轮流移动。\\
先将三子横、竖或斜连成一线为胜。无法移动则平局。")
    (history "Three Men's Morris is one of the oldest games known.  It was popular
       in ancient China, Greece, and Rome.  In Africa it is known as Jarabadach.
       This is the `Ludis terni lapilli` that Ovid (43 BC - AD 18) encouraged
       young girls to learn in his `Ars Amatoria`, or `Art of Love.`")
    ; ### Note: Gardner says: Since the first player has a sure win by playing
    ;     first in the center, this opening is usually barred.  With this
    ;     restriction the game is a draw if played rationally...
    (strategy "With perfect play, the first player can force a win.  See if you
		can find it!"); 
    (board
        (image "images\Morris\3_Mens_Morris.bmp")
        (grid
            (TMM-Grid)
            (directions (n -1 0) (e 0 1) (s 1 0) (w 0 -1))
         )
    )
    (piece
        (common-piece-stuff)
		(help "棋子必须全部落下之后，才可移动。")
		(moves
			(move-type moving)
			(shift n)
			(shift e)
			(shift s)
			(shift w)
        )
    )
)

(variant
    (title "Nine Holes")
	(description "每方持有3枚棋子，轮流落于棋盘上后，才可轮流移动，可移至任意空格。\\
先将三子横或竖连成一线为胜。")
    (history "Nine Holes is an old game played in many cultures.  It can be played 
	   anywhere since you only need 6 stones and 9 holes scooped in the ground.  It
       was popular in England hundreds of years ago.  An Ecclesiastical English court
       record surviving from 1699, describes a punishment given to two men for
       making nine-holes with their knives after evening prayers.  When colonists
       journeyed to New England, they took the playing of Nine Holes with them, despite
       the fact that Puritan laws forbade game playing.")
    (strategy "With careful play, Nine Holes should be a draw.  To win, try to threaten
       two different ways of making a row simultaneously.")
    (board
        (image "images\Morris\9holes.bmp" "images\Morris\9holes2.bmp")
        (grid
            (TMM-Grid)
            (directions (n -1 0) (e 0 1) (s 1 0) (w 0 -1))
         )
    )
    (win-condition (Green Blue)
        (or (absolute-config man (a1 a2 a3))
            (absolute-config man (a1 b1 c1))
            (absolute-config man (b1 b2 b3))
            (absolute-config man (c1 c2 c3))
            (absolute-config man (a3 b3 c3))
            (absolute-config man (a2 b2 c2))
		)
	)
)

(game
    (title "Les Pendus")
	(description "每方持有3枚棋子，轮流落于棋盘上后，才可轮流移动，可移至任意空格。\\
先将三子横、竖或斜连成一线为胜。")
    (history "`Les Pendus` (The Hanged) was a French version of Nine Holes.")
    (strategy "One author claimed that the starting player can win easily.  Zillions
       disagrees.  For your best shot at winning, try to threaten two different ways
       of making a row simultaneously.")
	(click-sound "Audio\\WoodClick.wav")
	(release-sound "Audio\\WoodClick.wav")
	(move-sound "Audio\\HollowClick.wav")
	(players Green Blue)
	(turn-order Green Blue)
	(move-priorities dropping moving)
    (option "prevent flipping" 2)
    (board
        (image "images\Morris\9holes.bmp" "images\Morris\9holes2.bmp")
        (grid (TMM-Grid))
    )
    (piece
        (common-piece-stuff)
		(help "棋子必须全部落下之后才可移动。")
		(moves
			(move-type moving)
			(shift a1) (shift a2) (shift a3)
			(shift b1) (shift b2) (shift b3)
			(shift c1) (shift c2) (shift c3)
		)
	)
    (board-setup
        (Green (man off 3))
        (Blue (man off 3))
    )
    (win-condition (Green Blue)
        (or (absolute-config man (a1 a2 a3))
            (absolute-config man (a1 b1 c1))
            (absolute-config man (a1 b2 c3))
            (absolute-config man (b1 b2 b3))
            (absolute-config man (c1 c2 c3))
            (absolute-config man (c1 b2 a3))
            (absolute-config man (a3 b3 c3))
            (absolute-config man (a2 b2 c2))
		)
	)
)

(variant
    (title "Les Pendus - Oldest Moves")
	(description "每方持有3枚棋子，轮流落于棋盘上后，才可轮流移动，但必须按照落子顺序1-2-3循环移动，可移至任意空格。\\
先将三子横、竖或斜连成一线为胜。\\")
    (history "This is a variant of an old game found in many cultures.")
    (strategy "Zillions thinks that with perfect play, this game should be a win for 
       the first player.  To win, consider
       which of your opponent's pieces will be forced to move.")
    (board
        (image "images\Morris\9holes.bmp" "images\Morris\9holes2.bmp")
        (grid (TMM-Grid))
        (positions (last -100 -100 -99 -99))
        (links next (a1 b1) (b1 c1) (c1 a2) (a2 b2) (b2 c2) (c2 a3) (a3 b3) (b3 c3) (c3 last))
    )
    (piece
        (common-piece-stuff2)
		(help "棋子必须全部落下之后才可移动，且必须按落子时的次序。")
		(moves
            (move-type moving)	
            (shift2 a1) (shift2 a2) (shift2 a3)
            (shift2 b1) (shift2 b2) (shift2 b3)
            (shift2 c1) (shift2 c2) (shift2 c3)
		)
	)
)

(variant (title "-")) ; ----------------------------------------------------------

; *** Tapatan
(variant
    (title "Tapatan")
	(description "每方持有3枚棋子，轮流落于棋盘上后，才可按线轮流移动。\\
先将三子横、竖或斜连成一线为胜。无法移动则平局。")
    (strategy "With perfect play, the first player can force a win.  See if you
		can find it!"); 
    ; ### VARIANT: Neither player may make the first move in the center:
    ;              Played in France and known as Marelle.
    (click-sound "Audio\\Tink.wav")
    (release-sound "Audio\\Metal4.wav")
    (move-sound "Audio\\Metal4.wav")
    (board
        (image "images\Morris\Tapatan.bmp" "images\Morris\Tapatan2.bmp")
        (grid
            (Tapatan-Grid)
            (directions (n -1 0) (e 0 1) (s 1 0) (w 0 -1))
		)
		(links ne (a1 b2) (b2 c3))
	    (links se (a3 b2) (b2 c1))
		(links nw (c1 b2) (b2 a3))
		(links sw (c3 b2) (b2 a1))
	)
    (piece
        (common-piece-stuff)
		(help "棋子必须全部落下之后才可移动。")
		(moves
			(move-type moving)
			(shift n)
			(shift e)
			(shift s)
			(shift w)
			(shift nw)
			(shift ne)
			(shift se)
			(shift sw)
		)
	)
)

; *** Achi
; Each player has four men of the same color.
; As in Three Men's Morris, men are introduced onto the board by
; alternate moves until all eight have been placed.  In the second
; phase men are moved along a line to a vacant point until one
; player succeeds in getting three men in a line to win.
; Stalemate is a draw.
(variant
    (title "Achi")
	(description "每方持有4枚棋子，轮流落于棋盘上后，才可按线轮流移动。\\
先将三子横、竖或斜连成一线为胜。无法移动则平局。")
	(history "This game was played by the Pueblo Indians of New Mexico, and must be a
       variation on Three Men's Morris games imported by the Spanish
       conquistadores in the 16th century.  Children play with stones, corn, or small
       pieces of pottery.")
    (strategy "With perfect play, Achi is a win for the first player.")
    (click-sound "Audio\\Tink.wav")
    (release-sound "Audio\\Metal4.wav")
    (move-sound "Audio\\Metal4.wav")
    (board
        (image "images\Morris\Tapatan.bmp" "images\Morris\Tapatan.bmp")
        (grid
            (Tapatan-Grid)
            (directions (n -1 0) (e 0 1) (s 1 0) (w 0 -1))
		)
		(links ne (a1 b2) (b2 c3))
	    (links se (a3 b2) (b2 c1))
		(links nw (c1 b2) (b2 a3))
		(links sw (c3 b2) (b2 a1))
	)
    (board-setup
        (Green (man off 4))
        (Blue (man off 4))
    )
    (piece
        (common-piece-stuff)
		(help "棋子必须全部落下之后才可移动。")
		(moves
			(move-type moving)
			(shift n)
			(shift e)
			(shift s)
			(shift w)
			(shift nw)
			(shift ne)
			(shift se)
			(shift sw)
         )
    )
)

(define Tant-Fant
   (history "This game is played in India.")
   (strategy "Tant Fant seems to be a draw with perfect play.")
   (click-sound "Audio\\Tink.wav")
   (release-sound "Audio\\Metal4.wav")
   (move-sound "Audio\\Metal4.wav")
   (board
        (image "images\Morris\Tapatan.bmp" "images\Morris\Tapatan.bmp")
        (grid
            (Tapatan-Grid)
            (directions (n -1 0) (e 0 1) (s 1 0) (w 0 -1))
		)
		(links ne (a1 b2) (b2 c3))
	    (links se (a3 b2) (b2 c1))
		(links nw (c1 b2) (b2 a3))
		(links sw (c3 b2) (b2 a1))
	)
    (board-setup
        (Blue (man a3 b3 c3))
        (Green (man a1 b1 c1))
    )
    (piece
        (common-piece-stuff)
		(help "棋子必须全部落下之后才可移动。")
		(moves
			(move-type moving)
			(shift n)
			(shift e)
			(shift s)
			(shift w)
			(shift nw)
			(shift ne)
			(shift se)
			(shift sw)
         )
    )
)
(variant
    (title "Tant Fant")
    (description "每方持有3枚棋子，可按线轮流移动。\\
先将三子横、竖或斜连成一线为胜。无法移动则平局。")
    (Tant-Fant)
	(win-condition (Green Blue)
        (or (absolute-config man (a1 a2 a3))
            (absolute-config man (a1 b2 c3))
            (absolute-config man (b1 b2 b3))
            (absolute-config man (c1 c2 c3))
            (absolute-config man (c1 b2 a3))
			(absolute-config man (a2 b2 c2))				
		)
	)
)
(variant
    (title "Tant Fant - Diagonals Only")
    (description "每方持有3枚棋子，轮流落于棋盘上后，才可按线轮流移动。\\
先将三子斜连成一线为胜。无法移动则平局。")
    (Tant-Fant)
	(win-condition (Green Blue)
        (or (absolute-config man (a1 b2 c3))
            (absolute-config man (c1 b2 a3))
		)
	)
)

(variant (title "-")) ; ----------------------------------------------------------

; *** Picaria
(variant
    (title "Picaria")
	(description "每方持有4枚棋子，轮流落于棋盘上后，才可按线轮流移动。\\
先将三子横、竖或斜连成一线为胜。无法移动则平局。")
    (history "Attributed to early American Indians.")
    ; ### VARIANTS: play on 13 points
    ; ### VARIANTS: more counters (on either 9 or 13 point)
    ; ### VARIANTS: Cannot drop to center (can move to it)
    ; ### VARIANTS: Row can be made anywhere along a diagonal (16 different ways)
    (board
        (image "images\Morris\Picaria.bmp" "images\Morris\Picaria2.bmp")
        (grid
            (Picaria-Grid)
            (directions (n -1 0) (e 0 1) (s 1 0) (w 0 -1)
                        (nw -1 -1) (ne -1 1) (sw 1 -1) (se 1 1)
            )
		)
	)
    (piece
        (common-piece-stuff)
		(help "棋子必须全部落下之后才可移动。")
		(moves
			(move-type moving)
			(shift n)
			(shift e)
			(shift s)
			(shift w)
			(shift nw)
			(shift ne)
			(shift se)
			(shift sw)
		)
	)
)

(variant
   (title "Modern Seega")
   (description "每方持有3枚棋子，可按线轮流移动。\\
先将三子横、竖或斜连成一线为胜。无法移动则平局。")
   (history "This game is played by young people in Egypt.")
   (strategy "With perfect play, Modern Seega appears to be a draw.")
   (board
        (image "images\Morris\Picaria.bmp" "images\Morris\Picaria2.bmp")
        (grid
            (Picaria-Grid)
            (directions (n -1 0) (e 0 1) (s 1 0) (w 0 -1)
                        (nw -1 -1) (ne -1 1) (sw 1 -1) (se 1 1)
            )
		)
	)
    (board-setup
        (Blue (man a3 b3 c3))
        (Green (man a1 b1 c1))
    )
    (piece
        (common-piece-stuff)
		(help "棋子必须全部落下之后才可移动。")
		(moves
			(move-type moving)
                        (slide n)
                        (slide e)
                        (slide s)
                        (slide w)
                        (slide ne)
                        (slide nw)
                        (slide se)
                        (slide sw)
         )
    )
    (win-condition (Green Blue)
        (or (absolute-config man (a1 a2 a3))
            (absolute-config man (a1 b2 c3))
            (absolute-config man (b1 b2 b3))
            (absolute-config man (c1 c2 c3))
            (absolute-config man (c1 b2 a3))
			(absolute-config man (a2 b2 c2))				
		)
	)
 )


; *** Tsoro Yematatu
(variant
    (title "Tsoro Yematatu")
    (description "每方持有3枚棋子，轮流落于棋盘上后，才可按线轮流移动。\\
先将三子横、竖或斜连成一线为胜。无法移动则平局。")
    (history "Tsoro Yematatu is an African game, popular among boys and men in Zimbabwe
        (Rhodesia). The name means `the stone game played with three`
        (`tatu` means three.)  Today children like to use bottle caps rather than
        stones.")
    (strategy "This is more difficult than it would seem at first glance, since
        there is only one free intersection available, once all the stones have
        been placed.")
    (option "prevent flipping" true)
    (board
        (image "images\Morris\Tsoro.bmp") ; images/tsoro.bmp
        (positions
            (a2  88 148 142 204)
            (a1  36 260  92 316)
            (b3 144  40 204  96)
            (b2 144 148 204 204)
            (b1 144 260 204 316)
            (c2 206 148 260 204)
            (c1 260 260 316 316)
		)
		(links ne (a1 a2) (a2 b3))
		(links nw (c1 c2) (c2 b3))
		(links e  (a2 b2) (b2 c2))
		(links n  (b1 b2) (b2 b3))
	)
    (board-setup
        (Green (man off 3))
        (Blue (man off 3)))
    (piece
        (common-piece-stuff)
		(help "棋子必须全部落下之后才可移动。")
		(moves
			(move-type moving)
			(shift a1) (shift a2)
			(shift b1) (shift b2) (shift b3)
			(shift c1) (shift c2)
		)
	)
    (win-condition (Green Blue)
        (or (absolute-config man (a1 a2 b3))
            (absolute-config man (b1 b2 b3))
            (absolute-config man (c1 c2 b3))
			(absolute-config man (a2 b2 c2))				
            (absolute-config man (a1 b1 c1))
		)
	)
)
